/* GUI CONVERTED from reclose.p (converter v1.76) Sun Aug 25 20:59:32 2002 */
/* reclose.p - REPETITIVE   CUM WORKORDER ACCTG CLOSE/WIP TRANSFER            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.13.3.13 $                                                               */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 11/03/94   BY: WUG *GN98*                */
/* REVISION: 7.3      LAST MODIFIED: 02/10/95   BY: srk *G0DS*                */
/* REVISION: 7.3      LAST MODIFIED: 03/29/95   BY: pma *F0PN*                */
/* REVISION: 8.5      LAST MODIFIED: 05/12/95   BY: pma *J04T*                */
/* REVISION: 8.5      LAST MODIFIED: 09/05/95   BY: srk *J07G*                */
/* REVISION: 7.3      LAST MODIFIED: 01/22/96   BY: emb *G1K9*                */
/* REVISION: 8.5      LAST MODIFIED: 03/13/96   BY: jym *G1GD*                */
/* REVISION: 8.5      LAST MODIFIED: 05/01/96   BY: jym *G1MN*                */
/* REVISION: 8.5      LAST MODIFIED: 05/13/96   BY: *G1S6* Julie Milligan     */
/* REVISION: 8.5      LAST MODIFIED: 06/03/96   BY: *G1VW* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 06/11/96   BY: ejh *K001*                */
/* REVISION: 8.5      LAST MODIFIED: 06/20/96   BY: *J0VG* Tamra Farnsworth   */
/* REVISION: 8.5      LAST MODIFIED: 07/26/96   BY: *J10X* Markus Barone      */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 03/31/98   BY: *J2H4* Niranjan R.        */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 08/20/99   BY: *N01B* John Corda         */
/* REVISION: 9.1      LAST MODIFIED: 09/29/99   BY: *N014* Jeff Wootton       */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 08/24/00   BY: *N0NM* Arul Victoria      */
/* REVISION: 9.1      LAST MODIFIED: 10/16/00   BY: *M0TS* Mark Christian     */
/* Revision: 1.13.3.10   BY: Jean Miller        DATE: 09/18/01  ECO: *N12P*   */
/* Revision: 1.13.3.11   BY: Robin McCarthy     DATE: 10/01/01  ECO: *P025*   */
/* Revision: 1.13.3.12   BY: Vivek Gogte      DATE: 01/18/02  ECO: *N17F*     */
/* $Revision: 1.13.3.13 $          BY: Vivek Gogte      DATE: 08/06/02  ECO: *N1QQ*     */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*V8:ConvertMode=Report                                                       */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reclose_p_1 "Update"
/* MaxLen: 9 Comment: FACILITATE SIMULATION MODE PRINTING */

&SCOPED-DEFINE reclose_p_2 "Total Cumulative Variance"
/* MaxLen: Comment: */

&SCOPED-DEFINE reclose_p_3 "Transfer WIP"
/* MaxLen: Comment: */

&SCOPED-DEFINE reclose_p_5 "Total Variance To Post"
/* MaxLen: Comment: */

&SCOPED-DEFINE reclose_p_8 "WIP Value"
/* MaxLen: Comment: */

&SCOPED-DEFINE reclose_p_10 "Cum Order Variance To Post"
/* MaxLen: Comment: */

&SCOPED-DEFINE reclose_p_11 "Cum Order Cumulative Variance"
/* MaxLen: Comment: */

&SCOPED-DEFINE reclose_p_12 "End Effective"
/* MaxLen: Comment: */

&SCOPED-DEFINE reclose_p_13 "Consolidated!Credit"
/* MaxLen: Comment: */

&SCOPED-DEFINE reclose_p_14 "Consolidated!Debit"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

/* PREPROCESSOR USED FOR REPORT'S WITH SIMULATION OPTION */
&SCOPED-DEFINE simulation true

{gldydef.i new}
{gldynrm.i new}

{gpglefv.i}

define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.
define new shared workfile work_op_recids no-undo
   field work_op_recid as recid.
define new shared workfile work_gltw no-undo like gltw_wkfl.
define new shared variable warn_ct as integer no-undo.

define variable cons_dr_amt like trgl_gl_amt column-label {&reclose_p_14}
   no-undo.
define variable cons_cr_amt like trgl_gl_amt column-label {&reclose_p_13}
   no-undo.
define variable eff_date like tr_effdate.
define variable end_wo_eff as date label {&reclose_p_12}.
define variable i as integer.
define variable line  like wo_line.
define variable line1 like wo_line label {t001.i}.
define variable lot   like wo_lot.
define variable lot1  like wo_lot label {t001.i}.
define variable part  like wo_part.
define variable part1 like wo_part label {t001.i}.
define variable site like wo_site.
define variable site1 like wo_site label {t001.i}.
define variable total_cum_var_amt  like glt_amt label {&reclose_p_2} no-undo.
define variable total_var_to_post  like glt_amt label {&reclose_p_5} no-undo.
define variable trans_type         as character.
define variable transfer_wip   like mfc_logical label {&reclose_p_3}.
define variable update_yn      like mfc_logical label {&reclose_p_1}.
define variable wip_value      like glt_amt column-label {&reclose_p_8}.
define variable xfer_wo_lot    as character.
define variable wo_cum_var_amt like glt_amt label {&reclose_p_11}.
define variable wo_var_to_post like glt_amt label {&reclose_p_10}.
define variable wip_tot        as decimal.
define variable c-msg1 like msg_desc no-undo.
define variable c-msg2 like msg_desc no-undo.
define variable c-msg3 like msg_desc no-undo.
define variable c-msg4 like msg_desc no-undo.
define variable msgdesc   like msg_desc no-undo.
define variable zero_unposted_var like mfc_logical initial yes no-undo.
define variable zero_cum_var      like mfc_logical initial yes no-undo.
define variable ptstatus  like pt_status no-undo.
define variable pagebreak like mfc_logical initial no no-undo.
define variable l_op like wr_op initial 0 no-undo.

define buffer womstr for wo_mstr.
define buffer xfer_wo_mstr for wo_mstr.

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i} /*CONSTANTS DEFINITIONS*/

if is_wiplottrace_enabled() then do:
   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}
   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}
end.

if can-find(first qad_wkfl where qad_key1 = "WO-CLOSE") then do:
   /* OLD WORK ORDER DATA STORAGE HAS BEEN DETECTED IN QAD_WKFL */
   {pxmsg.i &MSGNUM=1361 &ERRORLEVEL=1}
   /* PLEASE RUN "UTQADWO.P" BEFORE EXECUTING THIS FUNCTION     */
   {pxmsg.i &MSGNUM=1362 &ERRORLEVEL=1}
   pause.
   hide message no-pause.
   return.
end.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
lot                  colon 20
   lot1                 colon 45
   part                 colon 20
   part1                colon 45
   site                 colon 20
   site1                colon 45
   line                 colon 20
   line1                colon 45
   skip(1)
   end_wo_eff           colon 32
   eff_date             colon 32
   transfer_wip         colon 32
   update_yn            colon 32
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* ADD THE FOLLOWING FORM STATEMENT TO REPORT RECORES WITH */
/* SITES WHICH HAVE CLOSED GL PERIOD FOR THAT ENTITY       */
FORM /*GUI*/ 
   wo_lot
   wo_site
   msg_desc format "x(40)"
   si_entity
with STREAM-IO /*GUI*/  frame entity-closed width 132 no-attr-space down.

/* SET EXTERNAL LABELS */
setFrameLabels(frame entity-closed:handle).

/* ADD THE FOLLOWING FORM STATEMENT TO REPORT RECORDS WITH */
/* RESTRICTED ITEM STATUS CODES AND TRANSFER_WIP = YES     */
FORM /*GUI*/ 
   wo_lot
   wo_site
   msg_desc format "x(80)"
with STREAM-IO /*GUI*/  frame restricted width 132 no-attr-space down.

/* SET EXTERNAL LABELS */
setFrameLabels(frame restricted:handle).

find mfc_ctrl where mfc_field = "rpc_using_new" no-lock no-error.
if not available mfc_ctrl or mfc_logical = false then do:
   /* This module has not been enabled in Control File Maintenance */
   {pxmsg.i &MSGNUM=5119 &ERRORLEVEL=3}
   message.
   message.
   leave.
end.

for first gl_ctrl
   no-lock:
end. /* FOR FIRST gl_ctrl */

{gprun.i ""rerepma.p""}

find mfc_ctrl where mfc_field = "rpc_xfer_wip" no-lock.

assign
   transfer_wip = mfc_logical
   eff_date = today
   end_wo_eff = today - 1.

mainloop:
repeat:

   assign
      warn_ct = 0
      i = 0.

   if lot1  = hi_char then lot1 = "".
   if part1 = hi_char then part1 = "".
   if site1 = hi_char then site1 = "".
   if line1 = hi_char then line1 = "".

   update
      lot
      lot1
      part
      part1
      site
      site1
      line
      line1
      end_wo_eff
      eff_date
      transfer_wip
      update_yn
   with frame a.

   if end_wo_eff = ? then do:
      /* Invalid Date */
      {pxmsg.i &MSGNUM=27 &ERRORLEVEL=3}
      next-prompt end_wo_eff with frame a.
      undo, retry.
   end.

   bcdparm = "".

   {gprun.i ""gpquote.p""
      "(input-output bcdparm, 12,
        lot, lot1,
        part, part1,
        site, site1,
        line, line1,
        string(end_wo_eff), string(eff_date),
        string(transfer_wip), string(update_yn),
        null_char, null_char, null_char,
        null_char, null_char,
        null_char, null_char, null_char)" }

   if lot1 = "" then lot1 = hi_char.
   if part1 = "" then part1 = hi_char.
   if site1 = "" then site1 = hi_char.
   if line1 = "" then line1 = hi_char.

   /* SITE (RANGE-OF) SECURITY CHECK */
   if not batchrun then do:
      {gprun.i ""gpsirvr.p""
         "(input site, input site1, output return_int)"}
      if return_int = 0 then do:
         next-prompt site with frame a.
         undo mainloop, retry mainloop.
      end.
   end.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   {mfphead.i}

   for each gltw_wkfl exclusive-lock where gltw_batch = mfguser:
      delete gltw_wkfl.
   end.

   assign
      total_cum_var_amt = 0
      total_var_to_post = 0.

   /* Frame here from reuvpst so it would print on all pages of the output */
   FORM /*GUI*/ 
      skip(1)
      c-msg3 format "x(80)" no-label
   with STREAM-IO /*GUI*/  frame footer width 132 page-bottom.

   /* STANDARDS SHOWN ARE CONTAINED WITHIN THE CUMULATIVE WORK ORDER*/
   {pxmsg.i &MSGNUM = 3678 &MSGBUFFER = c-msg3}
   c-msg3 = getTermLabel("NOTE",8) + ": " + c-msg3.

   view frame footer.

   /* NOTE: THE by substr... CAUSES PROGRESS TO BUILD A SORT LIST,
    * NOT JUST PASS THE DATA ON THE INDEX.  THIS IS SO WE CAN CREATE
    * NEW WO'S AND AVOID HAVING THEM PROCESSED AS PART OF THE LIST. */

   wo-loop:
   for each wo_mstr
      fields (wo_acct_close wo_bom_code wo_close_date wo_close_eff wo_due_date
              wo_line wo_lot wo_nbr wo_part wo_routing wo_site wo_status
              wo_type wo_wip_tot)
      where wo_type = "c"
        and wo_status <> "c"
        and wo_lot >= lot and wo_lot <= lot1
        and wo_part >= part and wo_part <= part1
        and wo_site >= site and wo_site <= site1
        and wo_line >= line and wo_line <= line1
        and wo_due_date <= end_wo_eff
        and wo_nbr = ""
      no-lock
   use-index wo_type_part
   by wo_type by wo_site by wo_part
   by wo_line by wo_due_date by wo_lot:

      /* VALIDATE OPEN GL PERIOD FOR SPECIFIED ENTITY */
      for first si_mstr
         fields (si_entity si_site)
         where si_site = wo_site
         no-lock:
      end. /* FOR FIRST si_mstr ... */

      assign
         gpglef_entity = si_entity
         gpglef_effdate = eff_date
         gpglef_tr_type = "IC".

      {gprun.i ""gpglef1.p""
         "(input gpglef_tr_type,
           input gpglef_entity,
           input gpglef_effdate,
           output gpglef_result,
           output gpglef_msg_nbr)"}

      if gpglef_msg_nbr > 0 then do:
         if gpglef_result = 1 then do:
            /* Invalid Period/Year */
            {pxmsg.i &MSGNUM=3016 &ERRORLEVEL=1 &MSGBUFFER=c-msg4}
         end.
         else do:
            /* Period has been closed for entity */
            {pxmsg.i &MSGNUM=3036 &ERRORLEVEL=1 &MSGBUFFER=c-msg4}
         end.

         if pagebreak then page.

         display
            wo_lot
            wo_site
            c-msg4 @ msg_desc
            si_entity
         with frame entity-closed STREAM-IO /*GUI*/ .

         down 1 with frame entity-closed.

         pagebreak = no.
         next wo-loop.

      end. /* INVALID ENTITY */

      if transfer_wip then do:
         /* DO NOT ALLOW CREATION OF A CUMULATIVE WORK ORDER WHERE      */
         /* THE PART STATUS IS RESTRICTED AGAINST REPETITVE.            */
         /* THE # IN PT_STATUS IS USED TO DEFINE AN ITEM STATUS CODE,   */
         /* NO # IS FOR INVENTORY STATUS CODE.                          */
         for first pt_mstr
            fields (pt_part pt_status)
            where pt_part = wo_part
            no-lock:
         end. /* FOR FIRST pt_mstr ... */

         if available pt_mstr then do:

            assign
               ptstatus = pt_status
               substring(ptstatus,9,1) = "#".

            if can-find(isd_det where isd_status = ptstatus
                                  and isd_tr_type = "ADD-RE")
            then do:

               /* Unable to close with transfer. Restr proc for code */
               {pxmsg.i &MSGNUM=4870 &ERRORLEVEL=1 &MSGBUFFER=msgdesc}

               if pagebreak then page.

               display
                  wo_lot
                  wo_site
                  msgdesc @ msg_desc
               with frame restricted STREAM-IO /*GUI*/ .

               down 1 with frame restricted.

               pagebreak = no.
               next wo-loop.

            end. /* RESTRICTED ITEM STAUTUS COSE */

         end. /* AVAILABLE pt_mstr */

      end.  /* TRANSFER_WIP = YES */

      pagebreak = yes.

      page.

      for each work_gltw exclusive-lock:
         delete work_gltw.
      end.

      for each work_op_recids exclusive-lock:
         delete work_op_recids.
      end.

      do for womstr transaction:

         find womstr where recid(womstr) = recid(wo_mstr)
         exclusive-lock.

         /* REPORT AND POST USAGE VARIANCES */
         {gprun.i ""reuvpst.p""
            "(input wo_lot, input eff_date,
              output wo_cum_var_amt, output wo_var_to_post,
              input zero_unposted_var, input zero_cum_var)"}

         assign
            total_cum_var_amt = total_cum_var_amt + wo_cum_var_amt
            total_var_to_post = total_var_to_post + wo_var_to_post
            wip_tot = wo_wip_tot.

         /* Transfer WIP of this order to scrap account and close it */
         {gprun.i ""recloseb.p""
            "(input wo_mstr.wo_lot,
              input eff_date,
              input transfer_wip)"}

         if transfer_wip then do:

            for first wr_route
               fields (wr_nbr wr_lot wr_op)
               where wr_nbr = wo_nbr
                 and wr_lot = wo_lot
               no-lock:
               l_op = wr_op.
            end. /* FOR FIRST wr_route ... */

            /*TRANSFER WIP TO NEW ORDER ONLY IF THERE IS ANY WIP*/
            if (wip_tot <> 0) or
               can-find(first wr_route
                           where wr_nbr = wo_nbr
                             and wr_lot = wo_lot
                             and (((wr_qty_inque <> 0) and (wr_op > l_op))
                                or  (wr_qty_outque <> 0)
                                or  (wr_qty_rejque <> 0)))
            then do:

               /*FIND CUM ORDER.  CREATE IT IF IT DOESN'T EXIST*/
               {gprun.i ""regetwo.p""
                  "(input wo_site,
                    input wo_part,
                    input wo_due_date + 1,
                    input wo_line,
                    input wo_routing,
                    input wo_bom_code,
                    output xfer_wo_lot)"}

               if xfer_wo_lot = ? then do:
                  {gprun.i ""recrtwo.p""
                     "(input wo_site,
                       input wo_part,
                       input wo_due_date + 1,
                       input wo_line,
                       input wo_routing,
                       input wo_bom_code,
                       output xfer_wo_lot)"}
               end.

               do for xfer_wo_mstr:

                  for first xfer_wo_mstr
                     fields (wo_acct_close wo_bom_code wo_close_date
                             wo_close_eff wo_due_date wo_line wo_lot wo_nbr
                             wo_part wo_routing wo_site wo_status wo_type
                             wo_wip_tot)
                     where xfer_wo_mstr.wo_lot = xfer_wo_lot
                     no-lock:
                  end.   /* FOR FIRST xfer_wo_mstr ... */

                  if wo_status = "C" then do with frame u:

                     /*UNABLE TO TRANSFER, NEW ORDER IS CLOSED */
                     {pxmsg.i &MSGNUM=3677 &ERRORLEVEL=2 &MSGBUFFER=c-msg2}

                     /* SET EXTERNAL LABELS */
                     setFrameLabels(frame u:handle).

                     display
                        c-msg2 format "x(80)" no-label
                        wo_lot
                     with frame u side-labels width 132 STREAM-IO /*GUI*/ .

                     warn_ct = warn_ct + 1.

                  end.

                  else do:

                     /*TRANSFER WIP TO NEW ORDER*/
                     {gprun.i ""reclosea.p""
                        "(input wo_mstr.wo_lot,
                          input xfer_wo_lot,
                          input eff_date)"}
                  end.

               end.

            end.

            else do with frame t:

               /*  NO WIP BALANCES, NOT TRANSFERRING ORDER */
               {pxmsg.i &MSGNUM=3676 &ERRORLEVEL=2 &MSGBUFFER=c-msg1}

               /* SET EXTERNAL LABELS */
               setFrameLabels(frame t:handle).

               display
                  c-msg1 format "x(80)" no-label
                  wo_lot
               with frame t side-labels width 132 STREAM-IO /*GUI*/ .

               warn_ct = warn_ct + 1.

            end.

         end.

         if update_yn
         then do:

            for each wr_route where wr_lot = wo_lot
            exclusive-lock:
               assign
                  wr_qty_wip    = 0
                  wr_qty_inque  = 0
                  wr_qty_outque = 0
                  wr_qty_rejque = 0.
            end. /* FOR EACH wr_route */

         end. /* IF update_yn */

         for each work_op_recids,
             each op_hist no-lock
            where recid(op_hist) = work_op_recid,
             each opgl_det no-lock
            where opgl_trnbr = op_trnbr
         break by opgl_trnbr by opgl_gl_ref by opgl_sequence:

            display
               opgl_trnbr format ">>>>>>>9" when (update_yn = yes)
               opgl_gl_ref                  when (update_yn = yes)
               opgl_type
               op_wo_op
               opgl_dr_acct
               opgl_dr_sub
               opgl_dr_cc
               opgl_dr_proj
               opgl_cr_acct
               opgl_cr_sub
               opgl_cr_cc
               opgl_cr_proj
               opgl_gl_amt
            with width 132 STREAM-IO /*GUI*/ .

            create work_gltw.
            assign
               work_gltw.gltw_ref = opgl_gl_ref
               work_gltw.gltw_acct = opgl_dr_acct
               work_gltw.gltw_sub = opgl_dr_sub
               work_gltw.gltw_cc = opgl_dr_cc
               work_gltw.gltw_project = opgl_dr_proj
               work_gltw.gltw_date = op_tran_date
               work_gltw.gltw_effdate = op_date
               work_gltw.gltw_amt = opgl_gl_amt.

            create work_gltw.
            assign
               work_gltw.gltw_ref = opgl_gl_ref
               work_gltw.gltw_acct = opgl_cr_acct
               work_gltw.gltw_sub = opgl_cr_sub
               work_gltw.gltw_cc = opgl_cr_cc
               work_gltw.gltw_project = opgl_cr_proj
               work_gltw.gltw_date = op_tran_date
               work_gltw.gltw_effdate = op_date
               work_gltw.gltw_amt = - opgl_gl_amt.

         end.

         /* ADDED THE FOLLOWING TO MARK RECORD AS CLOSED * * */
         if update_yn then
            assign
               wo_acct_close = yes
               wo_close_date = today
               wo_close_eff  = eff_date.

         if is_wiplottrace_enabled() then do:
            run close_scrap_wip_lots in h_wiplottrace_procs
               (input womstr.wo_lot).
         end.

         if not update_yn then undo, leave.

      end.

      for each work_gltw:

         i = i - 1.

         create gltw_wkfl.
         assign
            gltw_wkfl.gltw_ref = work_gltw.gltw_ref
            gltw_wkfl.gltw_line = i
            gltw_wkfl.gltw_acct = work_gltw.gltw_acct
            gltw_wkfl.gltw_sub = work_gltw.gltw_sub
            gltw_wkfl.gltw_cc = work_gltw.gltw_cc
            gltw_wkfl.gltw_project = work_gltw.gltw_project
            gltw_wkfl.gltw_date = work_gltw.gltw_date
            gltw_wkfl.gltw_effdate = work_gltw.gltw_effdate
            gltw_wkfl.gltw_amt = work_gltw.gltw_amt
            gltw_wkfl.gltw_userid = mfguser
            gltw_wkfl.gltw_batch = mfguser.

      end.

   end.

   page.

   do with frame v:

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame v:handle).

      display
         total_cum_var_amt colon 66
         skip
         total_var_to_post colon 66
      with frame v side-labels width 132 STREAM-IO /*GUI*/ .

   end. /* do with */

   for each gltw_wkfl exclusive-lock
      where gltw_wkfl.gltw_batch = mfguser
        and gltw_wkfl.gltw_userid = mfguser
   break by gltw_wkfl.gltw_userid
         by gltw_wkfl.gltw_acct
         by gltw_wkfl.gltw_sub
         by gltw_wkfl.gltw_cc
         by gltw_wkfl.gltw_project:

      if first-of(gltw_wkfl.gltw_project) then do:
         assign
            cons_dr_amt = 0
            cons_cr_amt = 0.
      end.

      if gltw_wkfl.gltw_amt >= 0 then
         cons_dr_amt = cons_dr_amt + gltw_wkfl.gltw_amt.
      else
         cons_cr_amt = cons_cr_amt - gltw_wkfl.gltw_amt.

      if last-of(gltw_wkfl.gltw_project) then do:

         display
            space(40)
            gltw_wkfl.gltw_acct
            gltw_wkfl.gltw_sub
            gltw_wkfl.gltw_cc
            gltw_wkfl.gltw_project
            cons_dr_amt
            cons_cr_amt
         with width 132 STREAM-IO /*GUI*/ .

      end.

      delete gltw_wkfl.

   end.

   {mfrtrail.i}

   if warn_ct > 0 then do:
      /* Warning Messages Produced */
      {pxmsg.i &MSGNUM=8222 &ERRORLEVEL=2 &MSGARG1=warn_ct}
   end.

end.

if is_wiplottrace_enabled() then
   DELETE PROCEDURE h_wiplottrace_procs no-error.
if is_wiplottrace_enabled() then
   DELETE PROCEDURE h_wiplottrace_funcs no-error.
